Please remember this is a work in progress. Home » IntraWeb Components » Standard

Standard

 

TIWFile

 

The TIWFile is the IntraWeb component that adds File Upload capabilities to your application.

TIWFile = class(TIWCustomControl)

Properties

property BGColor: TIWColor

Use this property to set the background color of the IWEdit control that is rendered along with the TIWFile control.

property ButtonHeight: Integer

Use this property to set the height of the TIWButton control that is rendered along with the TIWFile control.

property FrameBGColor: TIWColor

Use this property to set the background color of the control.

Methods

procedure SaveToFile(AFilename: string = '');

Use this property to save the uploaded file to a file in the Server environment using the AFilename parameter. You need to include the full path on the AFilename parameter.

procedure SaveToStream(AStream: TStream);

Use this property to save the uploaded file to a Stream using the AStream parameter.

property ContentType: string read GetContentType;

Use this property to read the content type of the file being uploaded.

property Filename: string read FFileName;

Use this property to read the original name of the file being uploaded.

How to use the TIWFile component

Adding a TIWFile component to your IW form is not enough to start uploading files. For this to happen you need to have a control in your IW Form that is capable of triggering a full submit event, like a TIWButton. You need to add code to the TButton's OnClick event to save the file to another file on disk or to a stream. The Filename property contains only the name of the file without the full path file. This is a security restriction on Client's side as the Browser does not send local information to the requester.

Make sure you set the LockOnSubmit property to False in the IW form when you use a TIWFile.

  1. procedure TfrmUpload.UploadButtonClick(Sender: TObject);
  2. var
  3.   xDir: string;
  4. begin
  5.   xDir := URLPathToFilePath(IncludeTrailingBackslash(IWServerController.ContentPath), GetTopFolder);
  6.   IWFile.SaveToFile(xDir + IWFile.Filename);
  7.   MessageLabel.Visible := True;
  8.   MessageLabel.Caption := Format('New file "%s" uploaded to "%s"', [IWFile.Filename, xDir])
  9. end;

Note: The code above was extracted from the FileManager demo available in the IntraWeb demos

If the user has selected a file using the TIWFile options, the file will be uploaded to the server side when the user triggers a full submit event. In general, you will use a TIWButton to trigger the file upload and to save the file on server side, but you must be aware that if you have other control that can trigger a full submit event, like a TIWComboBox, your application needs to be prepared for that.

 

Terms of Use | Privacy Statement © 2002 - 2024 Atozed Software